package com.xy.cloud.config.exception.config;

import com.xy.cloud.config.exception.BusinessException;
import com.xy.cloud.domain.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 腥鱼 全局异常处理类
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public R<String> businessException(BusinessException exception) {
        String message = exception.getMessage();
        log.error("123捕获全局异常处理：{}", message);
        return R.fail(message);
    }

    @ExceptionHandler(Exception.class)
    public R<String> exception(Exception exception) {
        exception.printStackTrace();
        String message = exception.getMessage();
        log.error("捕获全局异常处理：{}", message);
        return R.fail(message);
    }


}
